package com.example.administrator.spritelgs.view;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;

import com.example.administrator.spritelgs.R;
import com.example.administrator.spritelgs.adapter.BeibaoAdapter;
import com.example.administrator.spritelgs.bean.BeibaoInfo;
import com.example.administrator.spritelgs.util.AnimUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/1.
 */

public class BeibaoView extends BaseView {
    private Dialog dialog;
    private ImageView iv_close;
    private GridView gv_beibao;

    public BeibaoView(Context context){
        super(context);
        setContentView(R.layout.view_beibao);

        initUI();
        initGvBeibaoAdapter();
    }
    @Override
    protected void initUI() {
        iv_close = (ImageView)findViewById(R.id.iv_close);
        AnimUtil.addOnTouchListener(iv_close, 0.5f, 0.5f, new AnimUtil.AnimListener() {
            @Override
            public void down(View v) {

            }

            @Override
            public void move(View v) {

            }

            @Override
            public void up(View v) {
                dialog.dismiss();
            }
        });

        gv_beibao = (GridView)findViewById(R.id.gv_beibao);
    }

    private void initGvBeibaoAdapter()
    {
        List<BeibaoInfo> data = new ArrayList<BeibaoInfo>();
        data.add(new BeibaoInfo(R.mipmap.ic_captain_jack,R.mipmap.att_fire,R.mipmap.rare1,R.mipmap.a_highlight,4,"LV.99"));
        data.add(new BeibaoInfo(R.mipmap.ic_drakan,R.mipmap.att_wind,R.mipmap.rare2,R.mipmap.a_highlight,4,"LV.87"));
        data.add(new BeibaoInfo(R.mipmap.ic_mermaidqueen,R.mipmap.att_wind,R.mipmap.rare3,R.mipmap.b_highlight,4,"LV.56"));
        data.add(new BeibaoInfo(R.mipmap.ic_oceantriton,R.mipmap.att_fire,R.mipmap.rare3,R.mipmap.s_highlight,4,"LV.54"));
        data.add(new BeibaoInfo(R.mipmap.ic_mermaid,R.mipmap.att_earth,R.mipmap.rare3,R.mipmap.a_highlight,4,"LV.11"));
        data.add(new BeibaoInfo(R.mipmap.ic_captain_jack,R.mipmap.att_fire,R.mipmap.rare2,R.mipmap.s_highlight,4,"LV.59"));
        data.add(new BeibaoInfo(R.mipmap.ic_mermaid,R.mipmap.att_water,R.mipmap.rare2,R.mipmap.c_highlight,4,"LV.42"));
        data.add(new BeibaoInfo(R.mipmap.ic_oceaking,R.mipmap.att_fire,R.mipmap.rare1,R.mipmap.s_highlight,4,"LV.57"));
        data.add(new BeibaoInfo(R.mipmap.ic_mermaidqueen,R.mipmap.att_water,R.mipmap.rare2,R.mipmap.d_highlight,4,"LV.78"));
        data.add(new BeibaoInfo(R.mipmap.ic_captain_jack,R.mipmap.att_fire,R.mipmap.rare2,R.mipmap.s_highlight,4,"LV.23"));
        BeibaoAdapter adapter = new BeibaoAdapter(context, data);
        gv_beibao.setAdapter(adapter);
    }

    public void show()
    {
        if(dialog == null) {
            dialog = new Dialog(context, R.style.MyDialog);
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            dialog.setContentView(view, params);
        }
        dialog.show();
    }
}
